<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>模拟微信服务器转发消息或事件</title>
</head>
<body>
<textarea id="msg-content" placeholder="发送给服务器的消息"></textarea>
<button onclick="sendText()">发送文本2</button>

<script>
    function sendText(){
        console.log("hello, will send text")
        const xmlData = setupMsgXml();
        console.log(xmlData);
        fetch('http://localhost:8080/wechat/monitor', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/xml'
            },
            body: xmlData
        })
            .then(response => response.text())
            .then(data => console.log(data))
            .catch(error => console.error('Error:', error));
        return "";
    }


    function setupMsgXml(){
        let xmlData = `
<xml>
    <ToUserName>云上漂服务号</ToUserName>
    <FromUserName>一个小粉丝</FromUserName>
    <CreateTime>1348831860</CreateTime>
    <MsgType>text</MsgType>
    <Content>hello world</Content>
    <MsgId>10001</MsgId>
    <MsgDataId>1</MsgDataId>
    <Idx>1</Idx>
</xml>
`;
    return xmlData;
    }


</script>
</body>
</html>